//
//  AuctionAvatarsView.swift
//  LeGou
//
//  Created by lxm on 2022/10/15.
//

import UIKit

class AuctionAvatarsView: LemonBaseView {

    //MARK: --------------------属性--------------------
    var avatars = [String]() {
        didSet {
           reload()
        }
    }
    
    var avatarsWidth : CGFloat = 18
    // 重叠距离
    var overlap : CGFloat = 4
    //MARK: --------------------UI控件--------------------
    
    //MARK: --------------------生命周期--------------------
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
        bindAction()
        addConstraints()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
        bindAction()
        addConstraints()
    }

    //MARK: --------------------UI--------------------
    func setUI() {
        reload()
    }
    
    func reload() {
        for i in 0 ..< avatars.count {
            let img = UIImageView()
            img.zm.setImage(urlStr: avatars[i])
            insertSubview(img, at: 0)
            img.cornerRadius = avatarsWidth / 2
            img.layer.borderWidth = 1
            img.layer.borderColor = UIColor.white.cgColor
            img.frame = CGRect(x: CGFloat(i) * (avatarsWidth - overlap), y: 0, width: avatarsWidth, height: avatarsWidth)
        }
        snp.remakeConstraints { make in
            let w = CGFloat(avatars.count) * (avatarsWidth - overlap) + (avatars.count > 0 ? overlap : 0)
            make.width.equalTo(w)
            make.height.equalTo(avatarsWidth)
        }
        layoutIfNeeded()
    }
    
    func addConstraints() {
     
    }
    
    //MARK: --------------------methods--------------------
    func bindAction() {
        
    }
    //MARK: --------------------delegate--------------------

}
